package Tools;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 资源信息格式化类
 * 
 * @author 紫夜
 * 
 */
public class InfoFormat {

	public static String FileMD5(File f) {
		return MD5.md5(f.getName() + "," + String.valueOf(f.length()) + "," + String.valueOf(f.lastModified()));
	}

	public static String FileTypeBewrite(String type) {
		return type;
	}

	public static String formatTime(long time) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(new Date(time));
	}

	/**
	 *  
	 *  转换成字符串描述
	 * @param time 秒单位
	 * @return
	 */
	public static String formatTimeGB(long time) {
//		SimpleDateFormat sdf = new SimpleDateFormat();
//		String timstr = sdf.format(new Date(time * 1000));
		return (time / 31536000 > 0 ? time / 31536000 +"年" : "") +(time%31536000 / 2419200 > 0 ?(time%31536000) / 2419200+"月" : "") +((time%2419200) / 86400 > 0 ? (time%2419200) / 86400+"天" : "") +((time%86400) / 3600 > 0 ? (time%86400) / 3600+"时" : "") + ((time%3600) / 60 > 0 ? (time%3600) / 60+"分" : "") +(time%60!=0?time%60+ "秒":"");
	}

	public static String getTypeStr(String filename) {
		String str = filename == null ? "" : filename;
		int i = str.lastIndexOf('.');
		return i == -1 ? "未知类型" : str.substring(i, str.length());
	}

	public static String shortString(String str, int sum) {
		return str.length() > sum ? str.substring(0, sum) + "..." : str;
	}
}
